<template>
    <a-modal v-model:open="visible" :title="title" :destroy-on-close="destroyOnClose" width="500px" :mask-closable="maskClosable" @ok="handleSubmit">
        <Form ref="formRef" />
    </a-modal>
</template>
<script setup>
import { nextTick, ref } from 'vue'
import { useModal } from '@iframe/tools/mixins/ModelDrawerMixins'
import Form from './Form.vue'
import { add, update } from '/@/api/System/Team'

const formRef = ref()
const title = ref('')
const { visible, destroyOnClose, maskClosable, close, submit } = useModal()

const emits = defineEmits(['close'])
const open = item => {
    visible.value = true
    if (item) {
        title.value = '修改团队'
        nextTick().then(() => {
            formRef.value.setForm(item)
        })
    } else {
        title.value = '新增团队'
    }
}
const handleSubmit = () => {
    submit({ formRef: formRef, save: add, update: update }).then(() => {
        emits('close')
        close()
    })
}
defineExpose({ open })
</script>
